package com.taxi.passengeruser.controller;

import com.taxi.common.dto.ResponseResult;
import com.taxi.common.request.VerificationCodeDTO;
import com.taxi.passengeruser.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.Method;

/**
 * @Author ruomengjiang
 * @Date 2022/7/8
 * @Description : online-taxi
 * @Version: 1.0
 */
@RestController
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 用户注册或登录
     * @param verificationCodeDTO
     * @return
     */
    @PostMapping("/user")
    public ResponseResult loginOrRegister(@RequestBody VerificationCodeDTO verificationCodeDTO){
        String passengerPhone = verificationCodeDTO.getPassengerPhone();
        //System.out.println("手机号："+passengerPhone);
        return userService.loginOrRegister(passengerPhone);
    }

    /**
     * 根据手机号查询用户信息
     * @param passengerPhone
     * @return
     */
    @GetMapping("/user/{phone}")
    //@RequestMapping(method = RequestMethod.GET,value = "/user/{phone}")
    public ResponseResult getUser(@PathVariable("phone") String passengerPhone){
        //System.out.println("service-passenger-user: phone:"+passengerPhone);
        return userService.getUserByPhone(passengerPhone);
    }

}
